layui.use(['table','jquery','layer','form'],function () {
    table = layui.table;
    $ = layui.jquery;
    layer = layui.layer;
    form = layui.form;

    var orderTable = table.render({
        elem:"#root",
        url:'/order/getAllReturnMsg?Status='+7,
        toolbar:'#toptool',
        defaultToolbar:['print','filter','exports'],
        page:true,
        limit:15,
        limits:[10,20,30],
        cols:[[
            {type:'checkbox',align:'center',width:60},
            {type:'orderId',title:'序号',align:'center',width:60,templet:function (data) {
                    return data.LAY_INDEX;
                }},
            {field:'nickname',title:'用户昵称',align:'center'},
            {field:'phone',title:'用户手机',align:'center'},
            {field:'orderSource',title:'订单来源',align:'center',templet:function (data) {
                    if (data.orderSource=="2"){
                        data.orderSource = "小程序";
                    }else if (data.orderSource=="3"){
                        data.orderSource = "app";
                    }
                    return "<p>"+data.orderSource+"</p>";
                }},
            {field:'orderStatus',title:'订单状态',align:'center',templet:function (data) {
                if (data.orderStatus=="2"){
                    data.orderStatus = "未付款";
                }else if (data.orderStatus=="3"){
                    data.orderStatus = "已付款";
                }else if(data.orderStatus=="4"){
                    data.orderStatus = "待发货";
                }else if(data.orderStatus=="5"){
                    data.orderStatus = "已发货";
                }else if(data.orderStatus=="6"){
                    data.orderStatus = "已签收";
                }else if(data.orderStatus=="7"){
                    data.orderStatus = "退货申请";
                }else if(data.orderStatus=="8"){
                    data.orderStatus = "退货中";
                }else if(data.orderStatus=="9"){
                    data.orderStatus = "已退货";
                }else if(data.orderStatus=="10"){
                    data.orderStatus = "取消交易";
                }else if(data.orderStatus=="11"){
                    data.orderStatus = "拒绝退货";
                }
                return "<p>"+data.orderStatus+"</p>";
            }},
            {field:'productName',title:'商品名称',align:'center'},
            {field:'productDescription',title:'商品描述',align:'center'},
            {field:'orderPaymentChannel',title:'支付渠道',align:'center',templet:function(data){
                if (data.orderPaymentChannel == "2"){
                    data.orderPaymentChannel = "微信支付";
                }else if (data.orderPaymentChannel =="3"){
                    data.orderPaymentChannel = "余额支付";
                }
                return "<p>"+data.orderPaymentChannel+"</p>";
            }},
            {field:'trueName',title:'商家名称',align:'center'},
            {field:'comment',title:'是否评论',align:'center',templet:function(data){
                if (data.comment == "2"){
                    data.comment = "待评论";
                }else if (data.comment =="3"){
                    data.comment = "已评论";
                }
                return "<p>"+data.comment+"</p>";
            }},
            {title:'操作',align:'center',templet:function (data) {
                var tem = '<a  href="javascript:getLogById('+data.productId+');" style="color:rgb(13,171,158)">查看</a>' +
                    '<a  href="javascript:removeLogById('+data.orderId+');" style="margin-left: 20px;color:rgb(13,171,158)">删除</a>';
                return tem;
            }},
        ]]
    });

    /* 搜索 */
    form.on('submit(sub)',function (data) {
        orderTable.reload({
            url:'/order/getAllReturnMsg?orderPaymentChannel='+data.field.orderPaymentChannel+'&orderSource='+data.field.orderSource+'&Status='+7
        });
        return false;
    });
    /* 重置 */
    form.on('submit(reset)',function (data) {
        orderTable.reload({
            url:'/order/getAllReturnMsg'
        });
    });
    /* 刷新 */
    form.on('submit(Refresh)',function (data) {
        orderTable.reload({
            url:'/order/getAllReturnMsg'
        });
    });
    /* 查看 */
    getLogById = function getLogById(productId) {
        $.ajax({
            url: "/goodsTable/getGoodsMsg",
            type: "post",
            dataType: "json",
            data: {"productId": productId},
            success: function (data) {
                devicesMsg(data);
            },
        })
    }

    function devicesMsg(data) {
        layer.open({
            type: 2,
            title: "详情",
            area: ['1000px', '700px'],
            maxmin: true,
            shade: 0,
            offset: 't',
            btn:['关闭'],
            content: "/goods/goods-see.html",
            success: function (layero, index) {
                var obj = layero.find('iframe').contents();
                obj.find("#productCode").val(data.data.productCode);
                obj.find("#productName").val(data.data.productName);
                obj.find("#currentpriceProduct").val(data.data.currentpriceProduct);
                obj.find("#title").val(data.data.title);
                if (data.data.productSate == 0) {
                    obj.find("#productSate").val("已删除");
                } else if (data.data.productSate == 1) {
                    obj.find("#productSate").val("上架");
                } else if (data.data.productSate == 2) {
                    obj.find("#productSate").val("下架");
                } else {
                    return "";
                }
                obj.find('#saleNum').val(data.data.saleNum);
                obj.find('#saleNum').val(data.data.saleNum);
                obj.find("#hits").val(data.data.hits);
                obj.find("#collectionNum").val(data.data.collectionNum);
                obj.find("#productDescription").val(data.data.productDescription);
                obj.find("#productLabel").val(data.data.productLabel);
                obj.find("#mainImage").attr('src',data.data.mainImage);
            }
        });
    }
    /*表格详情结束*/

    /* 删除 */
    removeLogById = function removeLogById(orderId){
        layer.confirm("确定删除？",{btn: ['确定', '取消'],title:"提示"}, function(){
            $.ajax({
                url:"/order/delCourseOrder",
                type:"post",
                dataType:"json",
                data:{"orderId":orderId},
                success:function(data){
                    if(data.data){
                        layer.msg("删除成功");
                        orderTable.reload();
                    }
                }
            })
        });
    };
    Refresh = function Refresh() {
        location.reload();
    }

    //返回
    goBack = function goBack() {
        parent.$('#beforeHref').val($('.layui-elem-quote').children('span').eq(0).text());
        parent.before();
        return false;
    }
});
